package top.szhome.framework.starter.db.configuration;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import top.szhome.framework.core.tools.constant.SzhomeConstant;

/**
 * Mybatis Plus配置
 * @author 唐加利
 * @date 2023/7/24
 **/
@AutoConfiguration
@PropertySource("classpath:/application-mybatis-plus.yml")
@MapperScan(SzhomeConstant.BASE_PACKAGE + ".**.mapper")
public class MybatisPlusAutoConfiguration {

    /**
     * Mybatis Plus插件
     * @return
     */
    @Bean
    @ConditionalOnMissingBean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
        paginationInnerInterceptor.setMaxLimit(10_000L);
        interceptor.addInnerInterceptor(paginationInnerInterceptor);

//        OrderInnerInterceptor orderInnerInterceptor = new OrderInnerInterceptor();
//        interceptor.addInnerInterceptor(orderInnerInterceptor);
        return interceptor;
    }

}
